package MiniZelda;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends Thread {
	JFrame window;
	JPanel game;
	Keyboard key = new Keyboard();
	Mouse m = new Mouse();
	Render rend = new Render(this);
	Intel intel = new Intel(rend);
	public boolean runapp = true;
	public void run() {
		drawGUI();
		mainLoop();
		
	}
	
	public static void main(String[] args) {
		new Main().start();
	}

	private void drawGUI() {
		window = new JFrame(Constants.NAME);
		window.setSize(Constants.WIDTH, Constants.HEIGHT);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		window.setIgnoreRepaint(true);
		window.setVisible(true);
		game = new JPanel();
		window.add(game);
		game.addKeyListener(key);
		game.addMouseListener(m);
		game.addMouseMotionListener(m);
		game.addMouseWheelListener(m);
		game.requestFocus();
	}
	public void mainLoop() {
		while (this.runapp ) {
			try {
				// 1. inputs are handled automatically and dont need to be called here
				// ---
				// 2. process game logic
				intel.process(key);
				// 3. draw to a buffer
				rend.render(intel);
				// 4. draw to a screen
				rend.display();
				// 5. wait a little
				try {
					Thread.sleep(10);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
	

	
}
